package org.idea.qiyu.framework.rocketmq.config.hook;

import org.apache.rocketmq.client.hook.FilterMessageContext;
import org.apache.rocketmq.client.hook.FilterMessageHook;
import org.apache.rocketmq.common.message.MessageExt;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Iterator;
import java.util.Map;


/**
 * @Author linhao
 * @Date created in 5:46 下午 2021/7/7
 */
public class MqMessageTraceHook implements FilterMessageHook {

    private static final Logger logger = LoggerFactory.getLogger(MqMessageTraceHook.class);

    @Override
    public String hookName() {
        return "MqMessageTraceHook";
    }

    @Override
    public void filterMessage(FilterMessageContext filterMessageContext) {
        Iterator<MessageExt> iterator = filterMessageContext.getMsgList().iterator();
        while (iterator.hasNext()) {
            MessageExt messageExt = iterator.next();
            Map<String,String> map = messageExt.getProperties();
            System.out.println(map);
        }
    }
}
